import Vue from 'vue'
import App from './App.vue'
import axios from 'axios'
import router from './router/index.js'
import ViewUI from 'view-design';
import 'view-design/dist/styles/iview.css';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.config.productionTip = false
Vue.use(ViewUI);
Vue.use(ElementUI);
//封装公共AJAX函数
Vue.prototype.ajaxs = (url, obj) => {
	var data = obj.data ? obj.data : {};
	axios({
		method: "POST",
		url: '/stage/' + url,
		data: data,
		headers: {
			'Content-Type': 'application/json',
			'x-requested-with': 'XMLHttpRequest'
		}
	})
		.then(res => {
      res = res.data;
      //登录失效
      if(res.code == 4) {
        location.reload();
        return false;
      }
			obj.success(res)
		})
		.catch(err => {
			obj.error && obj.error();
		}).catch(e => {
		})
};

router.beforeEach((to, from, next) => {
  ViewUI.LoadingBar.start();
  next();
});

router.afterEach(route => {
  ViewUI.LoadingBar.finish();
});

new Vue({
  router,
  render: h => h(App),
}).$mount('#app')
